package com.his.registration.controller;

import com.his.common.Result;
import com.his.dto.*;
import com.his.registration.service.CheckRequestService;
import com.his.registration.service.DisposalRequestService;
import com.his.registration.service.InspectionRequestService;
import com.his.registration.service.PrescriptionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @BelongsProject: workspace-idea
 * @BelongsPackage: com.his.registration.controller
 * @Author: ZhangYing
 * @Date: 2023/7/2 15:53
 * @Description:
 */
@RestController
@CrossOrigin
@RequestMapping("/charge")
public class ChargeController {
    @Autowired
    private CheckRequestService checkRequestService;
    @Autowired
    private InspectionRequestService inspectionRequestService;
    @Autowired
    private DisposalRequestService disposalRequestService;
    @Autowired
    private PrescriptionService prescriptionService;

    //查询患者所有的检查费用
    @RequestMapping("/getCheckFee")
    public Result getCheckFee(int registerId){
        List<CheckCharge> chargeList = checkRequestService.getCheckFee(registerId);
        List<CommonCharge> commonChargeList=new ArrayList<>();
        for (CheckCharge charge:
             chargeList) {
            CommonCharge commonCharge=new CommonCharge();
            commonCharge.setId(charge.getId());
            commonCharge.setChargeName(charge.getTechName());
            commonCharge.setChargePrice(charge.getTechPrice());
            commonCharge.setChargeType(charge.getTechType());
            commonCharge.setCreationTime(charge.getCreationTime());
            commonCharge.setState(charge.getCheckState());
            commonChargeList.add(commonCharge);
        }
        return Result.success(commonChargeList);
    }

    //查询患者所有的检验费用
    @RequestMapping("/getInspectionFee")
    public Result getInspectionFee(int registerId){
        List<InspectionCharge> chargeList = inspectionRequestService.getInspectionFee(registerId);
        List<CommonCharge> commonChargeList=new ArrayList<>();
        for (InspectionCharge charge:
                chargeList) {
            CommonCharge commonCharge=new CommonCharge();
            commonCharge.setId(charge.getId());
            commonCharge.setChargeName(charge.getTechName());
            commonCharge.setChargePrice(charge.getTechPrice());
            commonCharge.setChargeType(charge.getTechType());
            commonCharge.setCreationTime(charge.getCreationTime());
            commonCharge.setState(charge.getInspectionState());
            commonChargeList.add(commonCharge);
        }
        return Result.success(commonChargeList);
    }

    //查询患者所有的处置费用
    @RequestMapping("/getDisposalFee")
    public Result getDisposalFee(int registerId){
        List<DisposalCharge> chargeList = disposalRequestService.getDisposalFee(registerId);
        List<CommonCharge> commonChargeList=new ArrayList<>();
        for (DisposalCharge charge:
                chargeList) {
            CommonCharge commonCharge=new CommonCharge();
            commonCharge.setId(charge.getId());
            commonCharge.setChargeName(charge.getTechName());
            commonCharge.setChargePrice(charge.getTechPrice());
            commonCharge.setChargeType(charge.getTechType());
            commonCharge.setCreationTime(charge.getCreationTime());
            commonCharge.setState(charge.getDisposalState());
            commonChargeList.add(commonCharge);
        }
        return Result.success(commonChargeList);
    }

    //查询患者所有的药品费用
    @RequestMapping("/getDrugFee")
    public Result getDrugFee(int registerId){
        List<DrugCharge> chargeList = prescriptionService.getDrugFee(registerId);
        List<CommonCharge> commonChargeList=new ArrayList<>();
        for (DrugCharge charge:
                chargeList) {
            CommonCharge commonCharge=new CommonCharge();
            commonCharge.setId(charge.getId());
            commonCharge.setChargeName(charge.getDrugName());
            commonCharge.setChargePrice(charge.getDrugPrice());
            commonCharge.setChargeType(charge.getDrugType());
            commonCharge.setCreationTime(charge.getCreationTime());
            commonCharge.setState(charge.getDrugState());
            commonCharge.setDrugFormat(charge.getDrugFormat());
            commonCharge.setDrugNumber(charge.getDrugNumber());
            commonChargeList.add(commonCharge);
        }
        return Result.success(commonChargeList);
    }

    //缴费，设置各个state为"已缴费"
    @RequestMapping("/clssifyCharge")
    public Result clssifyCharge(int id,String chargeType){
        //根据前端的缴费类型选择来分别待用不同的缴费接口
        //检查缴费、检验缴费、处置缴费、药品缴费
        int result=0;
        String drugState="已缴费";
        if("检查缴费".equals(chargeType)){
            result = checkRequestService.charge(drugState,id);
        }
        if("检验缴费".equals(chargeType)){
            result = inspectionRequestService.charge(drugState,id);
        }
        if("处置缴费".equals(chargeType)){
            result = disposalRequestService.charge(drugState,id);
        }
        if("药品缴费".equals(chargeType)){
            result = prescriptionService.charge(drugState,id);
        }
        return Result.success(result+"条缴费成功");
    }
}
